<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.PreparedStatement" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.ResultSet" %>
<%--
  Created by IntelliJ IDEA.
  User: 113
  Date: 2020/10/20
  Time: 14:08
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
    <head>
        <title>Title</title>
        <link rel="stylesheet" href="css/bootstrap.css">

        <script src="js/jquery.min.js"></script>
        <script src="js/bootstrap.bundle.js"></script>
        <script src="js/bootstrap.js"></script>
    </head>
    <body>

        <%@ page contentType="text/html;charset=UTF-8" language="java" %>
        <div class="container">
            <div class="row clearfix">
                <div class="col-md-12 column">
                    <form role="form" method="post" action="update.jsp">
                        <h3 style="margin-top: 20px;">用户编辑</h3>
                        <%

                            int id = Integer.parseInt(request.getParameter("id"));

                            //查询用户信息
                            //加载驱动
                            Class.forName("com.mysql.jdbc.Driver");

                            //建立连接
                            String url ="jdbc:mysql://localhost:3306/book";
                            Connection connection = DriverManager.getConnection(url,"root","root");

                            //sql语句模板
                            String sql = "select * from user where id = ?";
                            //创建preparedStatement对象
                            PreparedStatement ps =connection.prepareStatement(sql);

                            int id = Integer.parseInt(request.getParameter("id"));
                            ps.setInt(1,id);

                            ResultSet rs =ps.executeQuery();


                            while (rs.next()){
                                out.print("<input type=\"hidden\" name='id' value="+id+">");
                                out.print("用户名：<input type='text' name='username' class=\"form-control\" value="+rs.getString("username")+"><br>");
                                out.print("密码：<input type='text' name='password' class=\"form-control\" value="+rs.getString("password")+"><br>");
                                out.print("性别：<input type='text' name='gender' class=\"form-control\" value="+rs.getString("gender")+"><br>");
                                out.print("年龄：<input type='text' name='age' class=\"form-control\" value="+rs.getString("age")+"><br>");
                            }
                        %>
                        <button type="submit" style="width: 100%" class="btn btn-info">提交</button>
                    </form>
                </div>
            </div>
        </div>

</body>
</html>
